const {
  createProxyMiddleware
} = require("http-proxy-middleware");

const proxy_api = 'http://192.168.3.63:38080' // 测试环境
// const proxy_api = 'http://192.168.50.81:38080' // 袁准
// const proxy_api = 'http://192.168.3.236:38080' // 研发环境
// const proxy_api = 'http://192.168.3.145:38080' // 测试环境
// const proxy_api = 'http://192.168.50.80:38080' // 吴永超
// const proxy_api = 'http://192.168.3.236:38080' // 郭德明
// const proxy_api = 'http://192.168.3.184:38080' //

module.exports = function (app) {
  app.use( // 大屏展示
    createProxyMiddleware(process.env.REACT_APP_window, {
      target: proxy_api,
      changeOrigin: true,
      pathRewrite: {
        ['^' + process.env.REACT_APP_window]: '/wpc-datawindow'
      }
    })
  );
  app.use( // 设计管理
    createProxyMiddleware(process.env.REACT_APP_design, {
      target: proxy_api,
      changeOrigin: true,
      pathRewrite: {
        ['^' + process.env.REACT_APP_design]: '/wpc-design'
      }
    })
  );
  app.use( // 勘测服务
    createProxyMiddleware(process.env.REACT_APP_survey, {
      target: proxy_api,
      changeOrigin: true,
      pathRewrite: {
        ['^' + process.env.REACT_APP_survey]: '/tnbs-survey'
      }
    })
  );
  app.use( // 报表服务
    createProxyMiddleware(process.env.REACT_APP_report, {
      target: proxy_api,
      changeOrigin: true,
      pathRewrite: {
        ['^' + process.env.REACT_APP_report]: '/wpc-report'
      }
    })
  );
  app.use( // 需求编制服务
    createProxyMiddleware(process.env.REACT_APP_demand, {
      target: proxy_api,
      changeOrigin: true,
      pathRewrite: {
        ['^' + process.env.REACT_APP_demand]: '/wpc-demand'
      }
    })
  );
  app.use( // 文件服务
    createProxyMiddleware(process.env.REACT_APP_file, {
      target: proxy_api,
      changeOrigin: true,
      pathRewrite: {
        ['^' + process.env.REACT_APP_file]: '/tnbs-filesystem'
      }
    })
  );
  app.use( // 项目中心
    createProxyMiddleware(process.env.REACT_APP_project, {
      target: proxy_api,
      changeOrigin: true,
      pathRewrite: {
        ['^' + process.env.REACT_APP_project]: '/project-center'
      }
    })
  );
  app.use( // 编制服务
    createProxyMiddleware(process.env.REACT_APP_bundle, {
      target: proxy_api,
      changeOrigin: true,
      pathRewrite: {
        ['^' + process.env.REACT_APP_bundle]: '/tnbs-bundle'
      }
    })
  );
  app.use( // 用户中心
    createProxyMiddleware(process.env.REACT_APP_basics, {
      target: proxy_api,
      changeOrigin: true,
      pathRewrite: {
        ['^' + process.env.REACT_APP_basics]: '/tnbs-basics'
        // ['^' + process.env.REACT_APP_basics]: ''
      }
    })
  );
  app.use( // 底图服务
    createProxyMiddleware(process.env.REACT_APP_tilemap, {
      target: proxy_api,
      changeOrigin: true,
      pathRewrite: {
        ['^' + process.env.REACT_APP_tilemap]: '/tilemap-center'
      }
    })
  );
  app.use( // 工程管控 & 里程碑服务
    createProxyMiddleware(process.env.REACT_APP_hnlcb, {
      target: proxy_api,
      changeOrigin: true,
      pathRewrite: {
        ['^' + process.env.REACT_APP_hnlcb]: '/wpc-hnlcb-dyy'
        // ['^' + process.env.REACT_APP_hnlcb]: '/wpc-hnlcb'
        // ['^' + process.env.REACT_APP_hnlcb]: '/wpc-hnlcb-shubo'
        // ['^' + process.env.REACT_APP_hnlcb]: '/hnlcb-service-lihui'
      }
    })
  );
};